package imp

import (
	sqlc "bgs/db/sqlc"
	"context"
	"fmt"
)

// getDistributorByUserIDAndStoreID
func (s *StoreAPIService) getDistributorByUserIDAndStoreID(ctx context.Context, q *sqlc.Queries, userID, storeID int64) (distributorPtr *sqlc.BrandDistributor, err error) {
	storePtr, err := s.storeService.GetStorePtr(ctx, q, storeID)
	if err != nil {
		return
	}
	if !storePtr.DistributorID.Valid {
		err = fmt.Errorf("不是分销门店")
		return
	}
	distributorPtr, err = s.brandService.GetDistributorPtr(ctx, q, storePtr.DistributorID.Int64)
	if err != nil {
		return
	}
	return
}